<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>index</title>
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css">
    <script src="http://apps.bdimg.com/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>
<body>
<h3>Auth index</h3>
<h3>当前用户：{{ request.user }}</h3>
{% if request.user.is_authenticated %}
    <p><button class="btn btn-danger exit">注销</button></p>
    {% else %}
    <p><button class="btn btn-danger login">登录</button></p>
{% endif %}
<script>
    $('.exit').click(function () {
        $.ajax({
            url: '{% url "auth_utils:logout" %}',
            type: 'post',
            data: {
                'csrfmiddlewaretoken': '{{ csrf_token }}'
            },
            success: function (res) {
                // 处理完请求后，刷新页面
                window.location.reload();
            },
        })
    })
    $('.login').click(function () {
        window.location.href = '{% url "auth_utils:login" %}';
    })
</script>
</body>
</html>